package top.yueyazhui.order.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.yueyazhui.common.bean.Response;
import top.yueyazhui.order.feign.AccountFeign;
import top.yueyazhui.order.mapper.OrderMapper;
import top.yueyazhui.order.service.OrderService;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    AccountFeign accountFeign;
    @Autowired
    OrderMapper orderMapper;

    @Override
    public boolean addOrder(String userId, String commodityCode, Integer count, Double money) {
        Response response = accountFeign.deductAccount(userId, money);
        int result = orderMapper.addOrder(userId, commodityCode, count, money);
        return result == 1 && response.getStatus() == 200;
    }
}
